Repository navigation
Shared JsonRepository base for all JSON repositories - #69
Merged
Merged
Conversation
RestaurantRepository now just passes its file path and model to the base, so customers/carts/orders can reuse the same loading and atomic saving instead of copying it. Public methods are unchanged. Updated two repository tests that patched the old module path and added tests for the base class.
Requests run in parallel threads, so two requests could both load the file and the second save would wipe out the first one's change. lock() gives one lock per JSON file that services can hold around load -> change -> save. Without it the new test only keeps 1 of 8 items.
CookieLynx
requested changes
Nov 17, 2026
CookieLynx
left a comment
Collaborator
There was a problem hiding this comment.
Looks Great! just one thing I would change.
Currently the _save_all catches only OSError's (disk full, no permission, etc). However if json.dump fails for a reason such as a data type thats invalid (TypeError or ValueError) it will not trigger the OSError block leaving the temp file on the disk forever and erroring the program.
Other then that I approve!
Before, only OSError cleaned it up, so a TypeError/ValueError from json.dump left a .tmp file behind (from Nathan's review). Cleanup is now in a finally block. OSError is still wrapped with the file path like before.
Collaborator
Author
|
good catch, fixed it
lmk if it looks good now |
CookieLynx
approved these changes
Nov 17, 2026
CookieLynx
left a comment
Collaborator
There was a problem hiding this comment.
New changes looking good! All tests pass! Handing of removing the file after regardless of errors is a good fix! Approved!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
My architectural improvement for M2. Moves the JSON load/save code out of RestaurantRepository into a shared JsonRepository base so customers, carts and orders don't copy it.